<template>
	<div class="add-node-btn-box">
		<div class="add-node-btn">
			<el-popover placement="right-start" :width="270" trigger="click" :hide-after="0" :show-after="0">
				<template #reference>
					<el-button type="primary" icon="el-icon-plus" circle></el-button>
				</template>
				<div class="add-node-popover-body">
					<ul>
						<li>
							<el-icon style="color: #ff943e;" @click="addType(1)"><el-icon-user-filled /></el-icon>
							<p>审批节点</p>
						</li>
						<li>
							<el-icon style="color: #3296fa;" @click="addType(2)"><el-icon-promotion /></el-icon>
							<p>抄送节点</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(4)"><el-icon-share /></el-icon>
							<p>条件分支</p>
						</li>
						<li>
							<el-icon style="color: #e73571;" @click="addType(5)"><el-icon-share /></el-icon>
							<p>并行分支</p>
						</li>
					</ul>
				</div>
			</el-popover>
		</div>
	</div>
</template>

<script setup>
import { ref } from 'vue'
import tool from '@/utils/tool'
import {deepClone} from '@/utils/arr.js'
const emit = defineEmits(['update:modelValue'])
const props = defineProps({
	modelValue: { type: Object, default: () => { } },
	currentNode: { type: Object, default: () => { } }
})
const addType = (type) => {
	var node = {}
	let oldNode = deepClone(props.modelValue)
	if (type == 1) {
		let id = tool.random.getRandomId()
		if(oldNode){
			oldNode.parentId = id
		}
		node = {
			"id": id,
			"nodeName": "审批人",
			"type": 1,
			"parentId": props.currentNode.id,
			//人员方式
			"assignedType": 1,
			//单选还是多选
			multiple: false,
			deptUserType: 'allUser',
			//多人审批的选项
			multipleMode: 1,
			//第几级部门负责人
			deptLeaderLevel: 1,
			//人员选择
			formUserId: "",
			formUserName: "",
			//表单权限
			formPerms: {},
			//审批人为空
			nobody: {
				handler: "TO_PASS",
				assignedUser: []
			},
			//审批人拒绝
			refuse: {
				handler: "TO_END",
				nodeId: ''
			},
			error: true,
			"childNode": oldNode,
			nodeUserList: []
		}
	} else if (type == 2) {
		let id = tool.random.getRandomId()
		if(oldNode.parentId){
			oldNode.parentId = id
		}
		node = {
			"id": tool.random.getRandomId(),
			"parentId": props.currentNode.id,
			error: true,
			"nodeName": "抄送人",
			"type": 2,
			"childNode": oldNode,
			nodeUserList: [],
		}

	} else if (type == 4) {
		let id = tool.random.getRandomId()
		if(oldNode){
			oldNode.parentId = id
		}
		node = {
			"nodeName": "条件分支",
			"type": 4,
			"id": id,
			"parentId": props.currentNode.id,
			"childNode": oldNode,
			"conditionNodes": [{
				"id": tool.random.getRandomId(),
				"nodeName": "条件1",
				"groupMode": true,
				"error": true,
				"type": 3,
				parentId: id,
				groupRelationMode: false,
				groupRelation: [],
				"priorityLevel": 1,
				"conditionList": [{
					mode: true,
					groupName: '条件组1',
					exp: 'c1',
					conditionList: [{
						key: '',
						keyType: '',
						mode: '',
						value: '',
						expression: '',
						conditionType: 'simple',
						comments: '',
						conditionSelectVal: [],
						deptList: [],
						employeeList: []
					}]
				}],
				"nodeUserList": [],
				"childNode": null,
			}, {
				"nodeName": "条件2",
				"type": 3,
				"id": tool.random.getRandomId(),
				"groupMode": true,
				"error": false,
				parentId: id,
				groupRelationMode: false,
				groupRelation: [],
				"priorityLevel": 2,
				"conditionList": [{
					mode: true,
					groupName: '条件组1',
					exp: 'c1',
					conditionList: [{
						key: '',
						keyType: '',
						mode: '',
						value: '',
						expression: '',
						conditionType: 'simple',
						comments: '',
						conditionSelectVal: [],
						deptList: [],
						employeeList: []
					}]
				}
				],
				"nodeUserList": [],
				"childNode": null
			}]
		}

	}
	else if (type == 5) {
		let id = tool.random.getRandomId()
		if(oldNode){
			oldNode.parentId = id
		}
		node = {
			"nodeName": "并行分支",
			"type": 5,
			"id": id,
			"parentId": props.currentNode.id,
			"childNode": oldNode,
			"conditionNodes": [{
				"id": tool.random.getRandomId(),
				"nodeName": "分支1",
				placeHolder: '满足条件',
				parentId: id,
				"error": false,
				"type": 3,
				"priorityLevel": 1,
				"conditionList": [],
				"nodeUserList": [],
				"childNode": null,
			}, {
				"nodeName": "分支2",
				"type": 3,
				"id": tool.random.getRandomId(),
				parentId: id,
				"error": false,
				placeHolder: '满足条件',

				"priorityLevel": 2,
				"conditionList": [],
				"nodeUserList": [],
				"childNode": null
			}]
		}
	}
	emit("update:modelValue", node)
}

</script>

<style></style>
